﻿<UserControl x:Class="tomenglertde.SetupProject.View.ProjectView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Model="clr-namespace:tomenglertde.SetupProject.Model;assembly=SetupProject.Model"
    xmlns:ViewModel="clr-namespace:tomenglertde.SetupProject.ViewModel;assembly=SetupProject.ViewModel">
  <UserControl.Resources>
    <HierarchicalDataTemplate DataType="{x:Type Model:NodeEntity}" ItemsSource="{Binding Path=Children}">
      <TextBlock Text="{Binding Path=Name}"/>
    </HierarchicalDataTemplate>
    <HierarchicalDataTemplate DataType="{x:Type ViewModel:SetupFile}" ItemsSource="{Binding Path=Children}">
      <TextBlock>
        <Run Text="{Binding Path=TargetName, Mode=OneWay}"/>
        <Run Text=":"/>
        <Run Text="{Binding Path=Id, Mode=OneWay}"/>
      </TextBlock>
    </HierarchicalDataTemplate>
    <HierarchicalDataTemplate DataType="{x:Type ViewModel:SetupProjectOutput}" ItemsSource="{Binding Path=Children}">
      <TextBlock>
        <Run Text="{Binding Path=OutputGroup, Mode=OneWay}"/>
        <Run Text=":"/>
        <Run Text="{Binding Path=ProjectGuid, Mode=OneWay}"/>
      </TextBlock>
    </HierarchicalDataTemplate>
  </UserControl.Resources>
  <TabControl DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}">
    <TabItem Header="Projects">
      <DataGrid ItemsSource="{Binding Path=ProjectMappings}" AutoGeneratedColumns="DataGridProjects_AutoGeneratedColumns" AutoGeneratingColumn="DataGrid_AutoGeneratingColumn"/>
    </TabItem>
    <TabItem Header="File">
      <DataGrid x:Name="DataGridFile" ItemsSource="{Binding Path=Project.Files}" KeyDown="DataGridFile_KeyDown" AutoGeneratingColumn="DataGrid_AutoGeneratingColumn">
        <DataGrid.ContextMenu>
          <ContextMenu>
            <MenuItem Header="Delete" Click="DataGridFile_DeleteClick"/>
          </ContextMenu>
        </DataGrid.ContextMenu>
      </DataGrid>
    </TabItem>
    <TabItem Header="Raw">
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition />
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <TreeView x:Name="treeView1"  Grid.Column="0" ItemsSource="{Binding Path=Project.Root.Children}"/>
        <GridSplitter Grid.Column="1" Width="3" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
        <ListBox Grid.Column="2" ItemsSource="{Binding Path=SelectedItem.Values, ElementName=treeView1}"/>
      </Grid>
    </TabItem>
    <TabItem Header="File Hierarchy">
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition />
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <TreeView x:Name="fileHierarchyList"  Grid.Column="0" ItemsSource="{Binding Path=Project.Files}"/>
        <GridSplitter Grid.Column="1" Width="3" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
        <TreeView Grid.Column="2" ItemsSource="{Binding Path=SelectedItem.Owners, ElementName=fileHierarchyList}">
          <TreeView.Resources>
            <HierarchicalDataTemplate DataType="{x:Type ViewModel:SetupFile}" ItemsSource="{Binding Path=Owners}">
              <TextBlock>
                <Run Text="{Binding Path=TargetName, Mode=OneWay}"/>
                <Run Text=":"/>
                <Run Text="{Binding Path=Id, Mode=OneWay}"/>
              </TextBlock>
            </HierarchicalDataTemplate>
          </TreeView.Resources>
        </TreeView>
      </Grid>
    </TabItem>
    <TabItem Header="Project Hierarchy">
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition />
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <TreeView x:Name="projectHierarchyList"  Grid.Column="0" ItemsSource="{Binding Path=Project.ProjectOutputs}"/>
        <GridSplitter Grid.Column="1" Width="3" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
        <ListBox Grid.Column="2" ItemsSource="{Binding Path=SelectedItem.Node.Values, ElementName=projectHierarchyList}"/>
      </Grid>
    </TabItem>
  </TabControl>
</UserControl>
